<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>人员管理</title>
<link href="${ctx}/style/upload.css" rel="stylesheet" />
<link href="${ctx}/style/font.css" rel="stylesheet" />
<script src="${ctx}/js/jquery-1.8.3.min.js"></script>
<script src="${ctx}/js/upload.js"></script>
<script type="text/javascript">

	function goToFileImport() {
		location.href = "${ctx}/admin/file";
	}

	//跳转到添加参加者页面
	function goToAddOne() {
		location.href = "${ctx}/admin/add";
	}
	
	
	$(function(){
		/*切换选中状态*/
		$(".i_input").live("click",function(){
			$(this).toggleClass("active");
		});
		/*关闭编辑框*/
		$(".colse_bg").live("click",function(){
			close_bg();
		});
		/*编辑会员信息*/
		$(".compile").live("click",function(){
			var this_clo = $(this).attr("clo");
			$(".bg_div button[clo]").attr("clo",this_clo);
			var name = $(this).parent("div").siblings("div[name='name']").text();
			$(".bg_div input[name='name']").val(name);
			var phone = $(this).parent("div").siblings("div[name='phone']").text();
			$(".bg_div input[name='phone']").val(phone);
			var code = $(this).parent("div").siblings("div[name='code']").text();
			$(".bg_div input[name='code']").val(code);
			var enterprise = $(this).parent("div").siblings("div[name='enterprise']").text();
			$(".bg_div input[name='enterprise']").val(enterprise);
			$(".bg").show(function(){
				$(".bg_div").show(300);
			});
		});
		/*保存修改*/
		$(".bg_int").live("click",function(){
			var this_clo = $(this).attr("clo");
			var name = $(".bg_div input[name='name']").val();
			var phone = $(".bg_div input[name='phone']").val();
			var code = $(".bg_div input[name='code']").val();
			var enterprise = $(".bg_div input[name='enterprise']").val();
			var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/; 
			if(!myreg.test(phone)){ 
				alert('请输入有效的手机号码！'); 
				return false; 
			}
		    //单独修改
		    var ok = singleModify(0,false,this_clo,name,phone,enterprise);
		    if(!ok){
		    	console.log('修改失败!');
		    	return faslse;
		    }
			$("#clo"+this_clo).find("div[name='name']").text(name);
			$("#clo"+this_clo).find("div[name='code']").text(code);
			$("#clo"+this_clo).find("div[name='enterprise']").text(enterprise);
			close_bg();
		});
		/*删除会员*/
		$(".close_id").live("click",function(){
			var this_clo = $(this).attr("clo");
			var ok = singleDel(1, false,this_clo);
			if(ok){
				console.log('删除成功!');
    			$("#clo"+this_clo).remove();
			}
		});
		/*打印*/
		$(".print_id").live("click",function(){
			var this_clo = $(this).attr("clo");
			var ok = singleDel(2, false,this_clo);
			console.log('开始打印。。。。。。');
			if(ok){
				console.log('打印成功!');
			}
		});
	});
	var ajaxSingleOperationUrl = ['${ctx}/admin/modify','${ctx}/admin/del','${ctx}/admin/print'];
	
	/*
	* 单独删除
	*/
	function singleDel(index,syc,id){
		return operation(index,syc, id);
	}
	/*
	* 单独修改
	*/
	function singleModify(index,syc,id,name,mobile,enterprise){
		return operation(index,syc, id, name, mobile,enterprise);
	}
	/*
	* 单独修改
	*/
	function singlePrint(index,syc,id){
		return operation(index,syc, id);
	}
	
	/*
	 * 根据ID进行数据操作
	 * @param id
	 */
	function operation(index,syc,id,name,mobile,enterprise){
		var ok = true;
		console.log('id :  ' +  id);
		$.ajax({
			"url" : ajaxSingleOperationUrl[index], //路径
			"cache" : false, //不缓存
			"async" : syc, //异步
			"type" : "POST", //POST方式提交
			"dataType" : "json", //json格式，重要
			// "contentType": "application/json",	  //json格式
			"data" : {
				'id' : id,
				'name':name,
				'mobile':mobile,
				'enterprise':enterprise
			}, //要提交的数据对象
			success : function(json) { //成功处理
				console.log('处理成功!');
				if(json.status == '1'){
     			  alertsimple(json.msg, 5000);
				  ok = false;
				}else{
				  console.log(json.msg);
				}
			},
			error : function(x, e) { //异常处理
				console.log(x);
				console.log(e);
				console.log('处理失败');
			}
		});
		return ok;
	}
	
	var ajaxUrl = ['${ctx}/admin/sms','${ctx}/admin/batchDel'];
	//中间通用逻辑 -- 发送短信和批量删除通用	
	function comomLogic(index,stop,tempIndex){
		var active_length = $(".i_input.active").size();
		var ids = "";
		var id = $(".i_input.active").eq(0).attr("id");
		ids += id;
		for(var i=1;i<active_length;i++){
			id = $(".i_input.active").eq(i).attr("id");
			ids += ","+id;
		}
		console.log("ids{ "+ ids.length +" }");
		if(ids === 'undefined'){
			 alertsimple("请选择一个活动者!", 5000);
			 return;
		}
		$(function(){
			$.ajax({
				"url" : ajaxUrl[index], //路径
				"cache" : false, //不缓存
				"async" : stop, //异步
				"type" : "POST", //POST方式提交
				"dataType" : "json", //json格式，重要
				// "contentType": "application/json",	  //json格式
				"data" : {
					'ids' : ids,
					tempIndex:tempIndex
				}, //要提交的数据对象
				success : function(json) { //成功处理
					console.log('处理成功!');
					if(json.status == '1'){
	     			  alertsimple(json.msg, 5000);
					}else{
					  alertsimple(json.msg, 5000);
					}
				},
				error : function(x, e) { //异常处理
					console.log(x);
					console.log(e);
					console.log('处理失败');
				}
			});
		});
	}
	
    var activiesId = "${activtites.id}";
    
	function sendSms(){
		$(".bgg").show(1,function(){
			$(".bgg_div").show(300);
		});
		//comomLogic(0,true);
	}
	/*关闭发送短信弹框*/
	function colse_bgg(){
		$(".bgg_div").hide(300,function(){
			$(".bgg").hide(1);
		});
	}
	function batchDel(){
		var stop = false;
		comomLogic(1,stop);
		location.href = "${ctx}/admin/list/1-"+activiesId;
    }
	
	$(function(){
		$('#search').click(function(){
			var keyCode =  $('#keyCode').val();
			console.log("keyCode:{ "+keyCode+" }");
			window.location = "${ctx}/admin/list/1-${activtites.id}-"+keyCode;
		});
		$('#keyCode').keydown(function(event){
			if(event.which == 13){
		    	var keyCode =  $('#keyCode').val();
	    		console.log("keyCode:{ "+keyCode+" }");
    			window.location = "${ctx}/admin/list/1-${activtites.id}-"+keyCode;
			}      
		});
		
	});
	

</script>
</head>

<body>
	<div class="upload">
		<div class="wid_100 lin_hd_60">
			<span class="mar_20">当前报名人数：<span class="color_red">${totalMen }</span>人
			</span> <span>当前付款人数：<span class="color_red">${pays }</span>人
			</span>
		</div>
		<div class="wid_100 lin_hd_60">
			<div class="flo_r relative wid_35 mar_20">
				<input class="wid_100 absolute top_0 font_14 lin_hd_40 bor_radius_20 pad_l_10" type="text" placeholder="想怎么提示怎么提示" id="keyCode"/>
				<i class="icon-quancheng495 absolute top_0 right_0 font_26" style="line-height:40px;" id="search"></i>
			</div>
			<button class="bth mar_20" onclick="goToAddOne()">添加参会者</button>
			<button class="bth mar_20" onclick="goToFileImport()">批量导入参会者</button>
			<button class="bth mar_20" onclick="batchDel()">批量删除</button>
			<button class="bth mar_20" onclick="sendSms()">发送短信</button>
		</div>
		<div class="wid_100 lin_hd_60 center bg_f2">
			<div class="wid_10 lin_hd_60">选择</div>
			<div class="wid_10 lin_hd_60">姓名</div>
			<div class="wid_15 lin_hd_60">电话</div>
			<div class="wid_15 lin_hd_60">企业名称</div>
			<div class="wid_10 lin_hd_60">签到码</div>
			<div class="wid_10 lin_hd_60">签到状态</div>
			<div class="wid_15 lin_hd_60">活动</div>
			<div class="wid_15 lin_hd_60">操作</div>
		</div>


		<div class="upload_content">

			<c:forEach items="${page.list}" var="av" varStatus="vIndex">
				<div class="wid_100 lin_hd_60 center bor_bottom" id="clo${av.id }">
					<div class="wid_10 lin_hd_60">
						<i class="i_input icon-quancheng1412 active" id="${av.id }"></i>
					</div>
					<div class="wid_10 lin_hd_60" name="id" hidden>${av.id }</div>
					<div class="wid_10 lin_hd_60" name="name">${av.activiter_name }</div>
					<div class="wid_15 lin_hd_60" name="phone">${av.activiter_mobile }</div>
					<div class="wid_15 lin_hd_60" name="enterprise">${av.enterprise }</div>
					<div class="wid_10 lin_hd_60" name="code">${av.sign_code }</div>
					<div class="wid_10 lin_hd_60">

						<c:choose>
							<c:when test="${av.sign_status == true}">
								<i class="img_input icon-quancheng1412"></i>
							</c:when>
							<c:otherwise>
								<i class="img_input_no icon-quancheng841"></i>
							</c:otherwise>
						</c:choose>

					</div>
					<div class="wid_15 lin_hd_60">${activtites.activites_name}</div>
					<div class="wid_15 lin_hd_60">
						<button class="bth mar_l_10 mar_t_10 compile" clo="${av.id }">编辑</button>
						<button class="bth mar_l_10 mar_t_10 close_id" clo="${av.id }">删除</button>
						<button class="bth mar_l_10 mar_t_10 print_id" clo="${av.id }">打印</button>
					</div>
				</div>
			</c:forEach>

		</div>
		<ul class="nav">


			<c:choose>
				<c:when test="${isFirstPage }">
					<a href="#"><i class="icon-quancheng310"></i>上一页</a>
				</c:when>
				<c:otherwise>
					<a href="${ctx}/admin/list/${page.pageNumber-1}-${activtites.id}"><i class="icon-quancheng310"></i>上一页</a>
				</c:otherwise>
			</c:choose>
         
            <span>|</span>
			<c:choose>
				<c:when test="${isLastPage }">
					<a href="#">下一页<i class="icon-quancheng306"></i></a>
				</c:when>
				<c:otherwise>
					<a
						href="${ctx}/admin/list/${page.pageNumber+1}-${activtites.id}">下一页<i class="icon-quancheng306"></i></a>
				</c:otherwise>
			</c:choose>
		</ul>
		<div class="wid_100 lin_hd_60">
			<span class="mar_20 color_red cursor" onclick="all_Checked()">全选</span>
			<span class="mar_20 color_red cursor" onclick="del_Checked()">取消全选</span>
			<span class="mar_20 color_red cursor" onclick="opposite_Checked()">反选</span>
		</div>
	</div>
	<div class="bg" hidden>
		<div class="bg_div" hidden>
			<div class="wid_100 lin_hd_60 center bg_0ea5fb color_fff">
				编辑参会者信息<i class="colse_bg img_input_no icon-quancheng841"></i>
			</div>
			<div class="wid_100 lin_hd_60">
				<span class="wid_20 right">姓名:</span> <input type="text" name="name"
					value="蔡晓青" class="bth_int mar_l_20" style="width: 300px;" />
			</div>
			<div class="wid_100 lin_hd_60">
				<span class="wid_20 right">电话:</span> <input type="text"
					name="phone" value="13421900600" disabled="disabled" class="bth_int mar_l_20"
					style="width: 300px;" />
			</div>
			<div class="wid_100 lin_hd_60">
				<span class="wid_20 right">企业名称:</span> <input type="text"
					name="enterprise" value="" class="bth_int mar_l_20" style="width: 300px;" />
			</div>
			<button class="bg_int wid_100 bg_0ea5fb cursor" clo="">修 改</button>
		</div>
	</div>
	
	<div class="bgg" hidden>
		<div class="bgg_div" hidden>
			<div class="wid_100 lin_hd_60 center bg_0ea5fb color_fff">
				选择发送信息模板<i class="colse_bgg img_input_no icon-quancheng841" onclick="colse_bgg();"></i>
			</div>
			<div class="flo_r relative wid_90 mar_20 mar_t_10 template_fun">
				<input class="wid_95 absolute top_0 font_14 lin_hd_40 bor_radius_20 pad_l_10" type="text" value="" name="" disabled="disabled" placeholder="请选择写短信模板">
				<i class="icon-quancheng570 absolute top_0 right_20 font_26" style="line-height:40px;"></i>
			</div>
			<div class="template" hidden>
			</div>
			<div class="template_div"></div>
			<button class="bgg_int wid_100 bg_0ea5fb cursor" onclick="">发送</button>
		</div>
	</div>
	<div class="template_detail" hidden>
	  <c:forEach items="${temps}" var="t" >
		<li>
		  ${t}
		</li>
	  </c:forEach>
	</div>
	<!--js弹出框功能-->
	<div id="insert" style="position: fixed; z-index: 2000;"></div>
	<script src="${ctx }/js/common.js"></script>
</body>
<script>
$(function(){
	var div_length = $(".template_detail li").size();
	var text_mun = "";
	for(var i=0;i<div_length;i++){
		text_mun += "<li>模板"+(i+1)+"</li>";
	}
	$(".template").html(text_mun);
	$(".template_fun").live("click",function(){
		$(".template").show();
	});
	$(".template li").live("click",function(){
		var text_mun = $(this).text();
		var this_index = $(this).index();
		var this_index_text = $(".template_detail li").eq(this_index).text();
		$(".template_div").text(this_index_text);
		$(".bgg_int").attr("onclick","sendSmsLogic(0,true,"+this_index+")");
		$(".template_fun input").val(text_mun);
		$(".template").hide();
	});
});
//发送短信逻辑，参数3 为选择的模板下标
function sendSmsLogic(index,stop,tempIndex){
	comomLogic(index,stop,tempIndex);
	$(".template").hide();
}
</script>
</html>